/* eslint-disable @typescript-eslint/no-explicit-any */
/*
 *  Copyright 2021 Collate
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

 /**
 * 测试用例是捕捉针对表、列和其他数据资产的数据质量测试的测试定义
 */
export interface TestCase {
    /**
     * 导致实体此版本的更改
     */
    changeDescription?: ChangeDescription;
    /**
     * Compute the passed and failed row count for the test case.
     */
    computePassedFailedRowCount?: boolean;
    /**
     * 当`true`表示实体已被软删除
     */
    deleted?: boolean;
    /**
     * 测试用例的描述
     */
    description?: string;
    /**
     * 标识此测试的显示名称
     */
    displayName?: string;
    /**
     * Domain the test case belongs to. When not set, the test case inherits the domain from the
     * table it belongs to.
     */
    domain?:    EntityReference;
    entityFQN?: string;
    entityLink: string;
    /**
     * Sample of failed rows for this test case.
     */
    failedRowsSample?: TableData;
    /**
     * 与`name`相同的FullyQualifiedName
     */
    fullyQualifiedName?: string;
    /**
     * 与此实体对应的资源链接
     */
    href?: string;
    /**
     * 此表实例的唯一标识符
     */
    id?: string;
    /**
     * Reference to an ongoing Incident ID (stateId) for this test case.
     */
    incidentId?: string;
    /**
     * SQL query to retrieve the failed rows for this test case.
     */
    inspectionQuery?: string;
    /**
     * 标识此测试用例的名称
     */
    name: string;
    /**
     * 此测试用例的所有者
     */
    owner?:           EntityReference;
    parameterValues?: TestCaseParameterValue[];
    /**
     * Tags for this test case. This is an inherited field from the parent entity and is not set
     * directly on the test case.
     */
    tags?: TagLabel[];
    /**
     * Latest test case result obtained for this test case.
     */
    testCaseResult?: TestCaseResult;
    testDefinition:  EntityReference;
    testSuite:       EntityReference;
    testSuites?:     TestSuite[];
    /**
     * 对应于实体新版本的最后更新时间，以Unix纪元时间毫秒表示
     */
    updatedAt?: number;
    /**
     * 进行更新的用户
     */
    updatedBy?: string;
    /**
     * 实体的元数据版本
     */
    version?: number;
}

/**
 * 导致实体此版本的更改
 *
 * Description of the change.
 *
 * 导致此实体版本的更改
 */
export interface ChangeDescription {
    /**
     * Names of fields added during the version changes.
     */
    fieldsAdded?: FieldChange[];
    /**
     * Fields deleted during the version changes with old value before deleted.
     */
    fieldsDeleted?: FieldChange[];
    /**
     * Fields modified during the version changes with old and new values.
     */
    fieldsUpdated?: FieldChange[];
    /**
     * When a change did not result in change, this could be same as the current version.
     */
    previousVersion?: number;
}

export interface FieldChange {
    /**
     * Name of the entity field that changed.
     */
    name?: string;
    /**
     * New value of the field. Note that this is a JSON string and use the corresponding field
     * type to deserialize it.
     */
    newValue?: any;
    /**
     * Previous value of the field. Note that this is a JSON string and use the corresponding
     * field type to deserialize it.
     */
    oldValue?: any;
}

/**
 * Domain the test case belongs to. When not set, the test case inherits the domain from the
 * table it belongs to.
 *
 * This schema defines the EntityReference type used for referencing an entity.
 * EntityReference is used for capturing relationships from one entity to another. For
 * example, a table has an attribute called database of type EntityReference that captures
 * the relationship of a table `belongs to a` database.
 *
 * 此测试用例的所有者
 *
 * 执行测试套件的实体引用，仅在测试套件可执行时适用
 *
 * 此测试用例定义的所有者
 *
 * 引用为此数据库服务部署的管道，用于提取元数据、使用情况、血统等
 *
 *
 * 此模式定义了用于引用实体的EntityReferenceList类型，EntityReference用于捕获从一个实体到另一个实体的关系。例如，表具有一个名为数据库的EntityReference类型的属性，该属性捕获表“属于”数据库的关系。
 */
export interface EntityReference {
    /**
     * If true the entity referred to has been soft-deleted.
     */
    deleted?: boolean;
    /**
     * Optional description of entity.
     */
    description?: string;
    /**
     * Display Name that identifies this entity.
     */
    displayName?: string;
    /**
     * Fully qualified name of the entity instance. For entities such as tables, databases
     * fullyQualifiedName is returned in this field. For entities that don't have name hierarchy
     * such as `user` and `team` this will be same as the `name` field.
     */
    fullyQualifiedName?: string;
    /**
     * Link to the entity resource.
     */
    href?: string;
    /**
     * Unique identifier that identifies an entity instance.
     */
    id: string;
    /**
     * If true the relationship indicated by this entity reference is inherited from the parent
     * entity.
     */
    inherited?: boolean;
    /**
     * Name of the entity instance.
     */
    name?: string;
    /**
     * Entity type/class name - Examples: `database`, `table`, `metrics`, `databaseService`,
     * `dashboardService`...
     */
    type: string;
}

/**
 * Sample of failed rows for this test case.
 *
 * This schema defines the type to capture rows of sample data for a table.
 */
export interface TableData {
    /**
     * List of local column names (not fully qualified column names) of the table.
     */
    columns?: string[];
    /**
     * Data for multiple rows of the table.
     */
    rows?: Array<any[]>;
}

/**
 * 该模式定义可用于测试用例的参数值
 */
export interface TestCaseParameterValue {
    /**
     * 参数的名称，必须与testCaseParameterDefinition中的参数名称匹配
     */
    name?: string;
    /**
     * 要传递给参数的值，这些值来自用户输入，我们在运行时捕捉此值并进行转换
     */
    value?: string;
    [property: string]: any;
}

/**
 * 此模式定义了用于使用标签标记实体的标签类型
 */
export interface TagLabel {
    /**
     * 标签标签的描述
     */
    description?: string;
    /**
     * 标识此标签的显示名称
     */
    displayName?: string;
    /**
     * 到标签资源的链接
     */
    href?: string;
    /**
     *
     * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
     */
    labelType: LabelType;
    /**
     * 标签或词汇术语的名称
     */
    name?: string;
    /**
     * 标签来自标签还是词汇表
     */
    source: TagSource;
    /**
     * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
     */
    state:  State;
    style?: Style;
    tagFQN: string;
}

/**
 *
 * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
 */
export enum LabelType {
    Automated = "Automated",
    Derived = "Derived",
    Manual = "Manual",
    Propagated = "Propagated",
}

/**
 * 标签来自标签还是词汇表
 */
export enum TagSource {
    Classification = "Classification",
    Glossary = "Glossary",
}

/**
 * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
 */
export enum State {
    Confirmed = "Confirmed",
    Suggested = "Suggested",
}

/**
 * UI Style is used to associate a color code and/or icon to entity to customize the look of
 * that entity in UI.
 */
export interface Style {
    /**
     * Hex Color Code to mark an entity such as GlossaryTerm, Tag, Domain or Data Product.
     */
    color?: string;
    /**
     * An icon to associate with GlossaryTerm, Tag, Domain or Data Product.
     */
    iconURL?: string;
}

/**
 * Latest test case result obtained for this test case.
 *
 * 用于捕获测试用例结果的模式
 */
export interface TestCaseResult {
    /**
     * Number of rows that failed.
     */
    failedRows?: number;
    /**
     * Percentage of rows that failed.
     */
    failedRowsPercentage?: number;
    /**
     * Incident State ID associated with this result. This association happens when the result
     * is created, and will stay there even when the incident is resolved.
     */
    incidentId?: string;
    /**
     * Number of rows that passed.
     */
    passedRows?: number;
    /**
     * Percentage of rows that passed.
     */
    passedRowsPercentage?: number;
    /**
     * 测试用例结果的详细信息
     */
    result?: string;
    /**
     * 用于捕获未匹配指定测试用例的行/列的示例数据
     */
    sampleData?: string;
    /**
     * standard test type: dataType, maxmuim, valuedomain, required
     */
    standardTestType?: string;
    /**
     * 测试用例运行的状态
     */
    testCaseStatus?:  TestCaseStatus;
    testResultValue?: TestResultValue[];
    /**
     * 获取测试用例结果的日期
     */
    timestamp?: number;
    [property: string]: any;
}

/**
 * 测试用例运行的状态
 *
 * 测试用例的状态
 */
export enum TestCaseStatus {
    Aborted = "Aborted",
    Failed = "Failed",
    Queued = "Queued",
    Success = "Success",
}

/**
 * 用于捕获测试用例结果值的模式
 */
export interface TestResultValue {
    /**
     * 值的名称
     */
    name?: string;
    /**
     * 值的名称
     */
    showName?: string;
    /**
     * 测试结果值
     */
    value?: string;
    [property: string]: any;
}

/**
 * TestSuite 是一组测试用例，用于捕获针对数据实体的数据质量测试
 */
export interface TestSuite {
    /**
     * 导致此实体版本的更改
     */
    changeDescription?: ChangeDescription;
    connection?:        TestSuiteConnection;
    /**
     * 当 `true` 时表示实体已被软删除
     */
    deleted?: boolean;
    /**
     * 测试套件的描述
     */
    description?: string;
    /**
     * 标识此测试套件的显示名称
     */
    displayName?: string;
    /**
     * 指示测试套件是否可执行在后端设置
     */
    executable?: boolean;
    /**
     * 执行测试套件的实体引用，仅在测试套件可执行时适用
     */
    executableEntityReference?: EntityReference;
    /**
     * 与 `name` 相同的完全限定名称
     */
    fullyQualifiedName?: string;
    /**
     * 指向与此实体对应的资源的链接
     */
    href?: string;
    /**
     * 此测试套件实例的唯一标识符
     */
    id?: string;
    /**
     * 标识此测试套件的名称
     */
    name: string;
    /**
     * 此测试用例定义的所有者
     */
    owner?: EntityReference;
    /**
     * 引用为此数据库服务部署的管道，用于提取元数据、使用情况、血统等
     */
    pipelines?: EntityReference[];
    /**
     * 数据库服务的类型，如 MySQL、BigQuery、Snowflake、Redshift、Postgres...
     */
    serviceType?: ServiceType;
    /**
     * 前一天此测试套件的测试用例执行摘要
     */
    summary?: TestSummary;
    /**
     * 测试用例执行摘要
     */
    testCaseResultSummary?: Array<any[] | boolean | number | number | null | TestCaseResultSummaryObject | string>;
    testConnectionResult?:  TestConnectionResult;
    tests?:                 EntityReference[];
    /**
     * 对应于实体的新版本的最后更新时间（Unix 纪元时间毫秒）
     */
    updatedAt?: number;
    /**
     * 进行更新的用户
     */
    updatedBy?: string;
    /**
     * 实体的元数据版本
     */
    version?: number;
}

export interface TestSuiteConnection {
    config?: null;
    [property: string]: any;
}

/**
 * 数据库服务的类型，如 MySQL、BigQuery、Snowflake、Redshift、Postgres...
 */
export enum ServiceType {
    TestSuite = "TestSuite",
}

/**
 * 前一天此测试套件的测试用例执行摘要
 *
 * 用于捕获测试用例执行摘要的模式
 */
export interface TestSummary {
    /**
     * 中止的测试用例数
     */
    aborted?:           number;
    columnTestSummary?: ColumnTestSummaryDefinition[];
    /**
     * 失败的测试用例数
     */
    failed?: number;
    /**
     * Number of test cases that are queued for execution.
     */
    queued?: number;
    /**
     * 通过的测试用例数
     */
    success?: number;
    /**
     * 总测试用例数
     */
    total?: number;
    [property: string]: any;
}

/**
 * Schema to capture test case execution summary at the column level.
 */
export interface ColumnTestSummaryDefinition {
    /**
     * Number of test cases that aborted.
     */
    aborted?:    number;
    entityLink?: string;
    /**
     * Number of test cases that failed.
     */
    failed?: number;
    /**
     * Number of test cases that are queued for execution.
     */
    queued?: number;
    /**
     * Number of test cases that passed.
     */
    success?: number;
    /**
     * Total number of test cases.
     */
    total?: number;
    [property: string]: any;
}

export interface TestCaseResultSummaryObject {
    /**
     * 测试用例的状态
     */
    status?: TestCaseStatus;
    /**
     * 测试用例的名称
     */
    testCaseName?: string;
    /**
     * 测试用例执行的时间戳
     */
    timestamp?: number;
    [property: string]: any;
}

/**
 * TestConnectionResult is the definition that will encapsulate result of running the test
 * connection steps.
 */
export interface TestConnectionResult {
    /**
     * Last time that the test connection was executed
     */
    lastUpdatedAt?: number;
    /**
     * Test Connection Result computation status.
     */
    status?: StatusType;
    /**
     * Steps to test the connection. Order matters.
     */
    steps: TestConnectionStepResult[];
}

/**
 * Test Connection Result computation status.
 *
 * Enum defining possible Test Connection Result status
 */
export enum StatusType {
    Failed = "Failed",
    Running = "Running",
    Successful = "Successful",
}

/**
 * Function that tests one specific element of the service. E.g., listing schemas, lineage,
 * or tags.
 */
export interface TestConnectionStepResult {
    /**
     * In case of failed step, this field would contain the actual error faced during the step.
     */
    errorLog?: string;
    /**
     * Is this step mandatory to be passed?
     */
    mandatory: boolean;
    /**
     * Results or exceptions to be shared after running the test. This message comes from the
     * test connection definition
     */
    message?: string;
    /**
     * Name of the step being tested
     */
    name: string;
    /**
     * Did the step pass successfully?
     */
    passed: boolean;
}
